package cn.codergege.demo.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.redis.connection.RedisConnectionFactory
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
import java.net.UnknownHostException
import org.springframework.cache.annotation.EnableCaching

@EnableCaching
@Configuration
class RedisConfig {
    @Bean
    @Throws(UnknownHostException::class)
    fun jsonRedisTemplate(redisConnectionFactory: RedisConnectionFactory): RedisTemplate<Any, Any> {
        val template = RedisTemplate<Any, Any>()
        template.setConnectionFactory(redisConnectionFactory)
        template.setDefaultSerializer(Jackson2JsonRedisSerializer<Any>(Any::class.java))
        return template
    }

    //Todo: redis 使用 json 序列化
}
